package com.yeban.controller;

import com.yeban.demo.User;
import com.yeban.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yeban
 * @desc TODO
 * @date 2025/9/5
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    // 查询用户
    @GetMapping("{id}")
    public User getUserById(@PathVariable("id") Integer id) {

        return userService.getById(id);
    }

    // 添加用户
    @PostMapping
    public boolean addUser(@RequestBody User user) {
        return userService.save(user);
    }

    // 删除用户
    @DeleteMapping("{id}")
    public boolean deleteUser(@PathVariable("id") Integer id) {
        return userService.removeById(id);
    }

    // 修改用户
    @PutMapping
    public boolean updateUser(@RequestBody User user) {
        return userService.updateById(user);
    }

}
